<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@page import="java.util.Date"%>
<%Date date=new Date();%>
<html>
<head>
	<title>补助标准管理</title>
	<meta name="decorator" content="default"/>
	<link type="text/css" rel="stylesheet" href="${ctxCss}/common/layerBtn.css" />
	<script type="text/javascript" src="${ctxScript}/js/subsidyStandard.js?<%=date.getTime()%>"></script>
	<script type="text/javascript">
        var path="${ctx}";
        var errorFlag1 = "0";
        var errorFlag2 = "0";
		$(document).ready(function() {
			vaccineTypeChange();
			$("#inputForm").validate({
				submitHandler: function(form){
				    if(errorFlag1 == "1" ||errorFlag2 == "1" ){
                        top.$.jBox.tip("请检查错误的内容！", "info");
						return false;
					}
                    $("#animalTypeName").val($("#animalTypeCode").find("option:selected").text());
                    $("#vaccineTypeName").val($("#vaccineTypeCode").find("option:selected").text());
                    $("#name").val($("#vaccineManageId").find("option:selected").text());

					//选全部企业时需验证疫苗唯一
                    if($("input[name='applyEntType']:checked").val() == "1"){
                        $.ajax({
                            url : path + "/bus/subsidyStandard/formValidate",
                            type : "post",
                            data : { "vaccineManageId": $("#vaccineManageId").val(),"applyEntType":$("#applyEntType").val()},
                            async : false,
                            success : function(data) {
                                if(data == "error"){
                                    top.$.jBox.tip("该疫苗已经维护过！", "info");
                                }else {
                                    $.ajax({
                                        url: path+"/bus/subsidyStandard/save",
                                        type: "post",
                                        data: $(form).serialize(),
                                        async : false,
                                        success : function(result) {
                                            top.$.jBox.tip("保存成功！", "info");
                                            parent.window.location.reload();
                                        }
                                    });
                                }
                            },
                            error : function(e) {
                            }
                        });
                    }else {
                        $.ajax({
                            url: path+"/bus/subsidyStandard/save",
                            type: "post",
                            data: $(form).serialize(),
                            async : false,
                            success : function(result) {
                                top.$.jBox.tip("保存成功！", "info");
                                parent.window.location.reload();
                            }
                        });
					}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});

            /**
			 * 企业类型改变时，企业选择框控制
			 * sy
             */
            $("input[name='applyEntType']").click(function () {
					if ($(this).val() == "1") {
							$("#chooseEntDiv").hide();
						} else {
                        $("#chooseEntDiv").show();
                    }
			});

            //三级联动初始化
           // animalTypeChange();
			//适用企业初始化
            if ($("input[name='applyEntType']:checked").val() == "1") {
                $("#chooseEntDiv").hide();
            } else {
                $("#chooseEntDiv").show();
            }
            <c:if test="${subsidyStandard.id != null and subsidyStandard.id !=''}">
            	<c:if test="${subsidyStandard.applyEntType == '1'}">
						$("#chooseEntDiv").hide();
				</c:if>
				<c:if test="${subsidyStandard.applyEntType == '2'}">
					$("#chooseEntDiv").show();
				</c:if>
			</c:if>
        });
	</script>
</head>
<body>
<br>
	<form:form id="inputForm" modelAttribute="subsidyStandard" action="" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="animalTypeName"/>
		<form:hidden path="vaccineTypeName"/>
		<form:hidden path="name"/>
		<sys:message content="${message}"/>
		<c:choose>
		    <c:when test="${subsidyStandard.id == null or subsidyStandard.id ==''}">
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>疫苗品种：</label>
					<div class="controls">
						<form:select path="vaccineTypeCode" htmlEscape="false"  maxlength="4" class="input-xlarge required" style="width:350px;" onchange="vaccineTypeChange()">
							<form:options items="${vaccineTypeList}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>疫苗名称：</label>
					<div class="controls">
						<form:select path="vaccineManageId" htmlEscape="false"  maxlength="50" class="input-xlarge required" style="width:350px;" onchange="changeEnt()">
						</form:select>
					</div>
				</div>
		    </c:when>
		    <c:otherwise>
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>疫苗品种：</label>
					<div class="controls">
							${subsidyStandard.vaccineTypeName}
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>疫苗名称：</label>
					<div class="controls">
							${subsidyStandard.name}
					</div>
				</div>
		    </c:otherwise>
		</c:choose>
		<div class="control-group">
			<label class="control-label"><span style="color:red">*</span>补助标准：</label>
			<div class="controls">
				<form:input path="standardNum" htmlEscape="false" maxlength="10" class="input-small required"/>
				<form:select path="standardTypeCode" class="input-largexx" maxlength="20" style="width:100px;">
					<form:options items="${fns:getDictList('standardType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<c:choose>
		    <c:when test="${subsidyStandard.id != null and subsidyStandard.id !=''}">
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>适用企业：</label>
					<div class="controls">
						<c:if test="${subsidyStandard.applyEntType == '1'}">
							全部企业
						</c:if>
						<c:if test="${subsidyStandard.applyEntType == '2'}">
							个别企业
						</c:if>
					</div>
				</div>
		    </c:when>
		    <c:otherwise>
				<div class="control-group">
					<label class="control-label"><span style="color:red">*</span>适用企业：</label>
					<div class="controls">
						<form:radiobutton path="applyEntType" value="1" checked="true" />全部企业&emsp;
						<form:radiobutton path="applyEntType" value="2" />个别企业<br/>
					</div>
				</div>
		    </c:otherwise>
		</c:choose>

		<div class="control-group" id="chooseEntDiv" style="display: none">
			<label class="control-label"><span style="color:red">*</span>选择企业：</label>
			<div class="controls">
				<form:select path="entList" class="input-largexx required" maxlength="2000" style="width:350px;" onchange="changeEnt()">
					<form:options items="${entList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
	</form:form>
</body>
</html>